<template>
  <a-form :form="form.structure">
    <a-row :gutter="16">
      <a-col :lg="6" :md="12" :sm="24">
        <a-form-item label="出库单号">
          <a-input-search
            :disabled="disabled"
            v-decorator="['code', { rules: [{required:true}] }]"
            read-only
            placeholder="请选择出库单"
            @search="handleOrderSelect">
            <a-button slot="enterButton" style="color: #1890ff;font-weight: 500">
              选择
            </a-button>
          </a-input-search>
        </a-form-item>
      </a-col>
      <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
        <a-form-item label="出库时间">
          <a-input v-decorator="['outRepoTime', { initialValue:code(true), rules: [{required:true}] }]" read-only />
        </a-form-item>
      </a-col>
      <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
        <a-form-item label="仓库管理员">
          <a-input read-only v-decorator="['repoManager', { initialValue: repoManager, rules: [{required: true}] }]">
            <a-icon slot="prefix" type="user"/>
          </a-input>
        </a-form-item>
      </a-col>
    </a-row>
    <a-row :gutter="16">
      <a-col :lg="6" :md="12" :sm="24">
        <a-form-item label="审核员">
          <a-select
            :disabled="disabled"
            placeholder="请选择"
            v-decorator="['auditor', {
              rules: [{required: true, message: '请选择审核员！'}]
            }]">
            <a-select-option v-for="(item, index) in form.auditorList" :key="index" :value="item">
              {{ item }}
            </a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
      <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
        <a-form-item label="备注">
          <a-input :disabled="disabled" v-decorator="['outRepoRemark', {rules: [{required:true}] }]"/>
        </a-form-item>
      </a-col>
    </a-row>
  </a-form>
</template>

<script>
import randomCode from '../../purchase/utils/randomCode'
import { auditorList } from '@/api/sale'

export default {
  name: 'SaleOutBasic',
  data () {
    return {
      repoManager: this.$store.getters.nickname,
      code (boolean) {
        return boolean ? randomCode(boolean) : randomCode()
      },
      form: {
        auditorList: [],
        structure: this.$form.createForm(this)
      }
    }
  },
  props: {
    disabled: {
      type: Boolean,
      default: false
    }
  },
  created () {
    this.getAuditorList()
  },
  methods: {
    getAuditorList () {
      const _this = this
      auditorList()
      .then(res => {
        _this.form.auditorList = res.data.auditorList
      })
      .catch(err => {
        _this.$message.error(err.response || '获取审核员列表失败')
      })
    },
    handleOrderSelect () {
      this.$emit('orderModalOpen')
    }
  }
}
</script>

<style lang="less" scoped>
.ant-form-item {
  margin-bottom: 10px;
}
</style>
